//
//  HJChatUserModel.m
//  KaiChat
//
//  Created by lx on 2023/10/20.
//

#import "HJChatUserModel.h"
#import "HJChatFriendModel.h"


@implementation HJChatUserModel

MJLogAllIvars


+ (NSArray *)bg_uniqueKeys {
    return @[@"userId"];
}

+ (NSArray *)bg_ignoreKeys {
    return @[@"showName"];
}
 
- (NSString *)bg_tableName {
    return [NSString stringWithFormat:@"%@", NSStringFromClass(self.class)];
}

+ (NSString *)bg_tableName {
    return [NSString stringWithFormat:@"%@", NSStringFromClass(self.class)];
}

 
+ (HJChatUserModel *)modelWithDict:(NSDictionary *)dict {
    
    NSArray *allKeys = dict.allKeys;
    
    HJChatUserModel *model = [[HJChatUserModel alloc] init];
    model.status = [dict[@"status"] intValue];
    model.relationship = [dict[@"relationship"] intValue];
    model.way = [dict[@"way"] intValue];
    model.avatar = dict[@"profile_picture"];
    if ([allKeys containsObject:@"user_nickname"]) {
        model.nickname = dict[@"user_nickname"];
    } else {
        model.nickname = dict[@"nickname"];
    }
    model.remarks = dict[@"comment"];
    model.brief = dict[@"brief"];
    model.uid = dict[@"uid"];
    if ([allKeys containsObject:@"im_session_id"]) {
        model.sessionId = toString(dict[@"im_session_id"]);
    }
    if ([allKeys containsObject:@"id"]) {
        model.userId = toString(dict[@"id"]);
    }
    return model;
}

+ (HJChatUserModel *)modelWithFriendModel:(HJChatFriendModel *)friendModel {
    
    HJChatUserModel *model = [[HJChatUserModel alloc] init];
    model.userId = friendModel.userId;
    model.relationship = 1;
    model.avatar = friendModel.avatar;
    model.nickname = friendModel.nickname;
    model.remarks = friendModel.remarks;
    model.brief = friendModel.brief;
    model.uid = friendModel.uid;
    model.sessionId = toString(friendModel.sessionId);
    return model;
}


+ (HJChatUserModel *)modelWithBlock:(void (^)(HJChatUserModel *model))block {
    HJChatUserModel *model = [[HJChatUserModel alloc] init];
    if (block) block(model);
    return model;
}

- (NSString *)showName {
//    if (!isEmptyString(self.remarks)) {
//        return self.remarks;
//    }
    if (!isEmptyString(self.nickname)) {
        return self.nickname;
    }
    if (!isEmptyString(self.uid)) {
        return self.uid;
    }
    return toString(self.userId);
}

- (BOOL)isFridend {
    return self.relationship == 1;
}

@end
